﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.CodeDom;
using devtm.Editor.TypeSelector;


namespace devtm.Templates.Helpers
{
    public static class Helper
    {


        #region Declare
       
        public static MyRef Declare(this CodeStatementCollection code, MyRef newLine)
        {
            code.Add(new MyRefStatement(newLine));
            return newLine;
        }

        public static MyRef Declare(this CodeStatementCollection code, string variableName, BuildTypeExpression type)
        {
            return Declare(code, new MyRef(variableName, (MyType)type));
        }

        public static MyRef Declare(this CodeStatementCollection code, string variableName, BuildTypeExpression type, CodeExpression initExpression)
        {
            var t = new MyRef(variableName, (MyType)type);
            var i = new MyRefStatement(t, initExpression);
            code.Add(i); 
            return t;
        }

        public static MyRef Declare(this CodeStatementCollection code, string variableName, MyProperty property)
        {
            var t = new MyRef(variableName, property.Type);
            var i = new MyRefStatement(t, property);
            code.Add(i);
            return t;
        }

        public static MyRef Declare(this CodeStatementCollection code, MyRef newLine, CodeExpression initExpression)
        {
            code.Add(new MyRefStatement(newLine, initExpression));
            return newLine;
        }

        #endregion


        public static T WriteLine<T>(this CodeStatementCollection code, T newLine)
            where T : CodeExpression
        {
            code.Add(newLine);
            return newLine;
        }


        public static MyForEach ForEach(this CodeStatementCollection code, MyRef source, string nameVariable)
        {
            var f = new MyForEach(code, source, nameVariable);
            code.Add(f);
            return f;
        }


    }

    //public static class CodeStatementHelper
    //{

    //    public static T WriteLine<T>(this CodeStatementCollection code, T newLine)
    //                where T : CodeStatement
    //    {
    //        code.Add(newLine);
    //        return newLine;
    //    }
    //}

}
